package com.pulse.common.utils.sor.make;

import com.pulse.common.utils.sor.domain.SorInfo;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 * @ClassName CksumMake
 * @Description
 * @Author 陆帅
 * @Date 2025/3/14 23:27
 */
public class CksumMake {

    public static final String CK_SUM_BLOCK_ID = "Cksum\0";

    public static ByteBuffer make(SorInfo info) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.order(ByteOrder.LITTLE_ENDIAN);

        // 块ID
        buffer.put(CK_SUM_BLOCK_ID.getBytes());
        // 校验和
        Long checkSum = info.getCksum().getChecksum() == null ? 0 : info.getCksum().getChecksum();
        buffer.putShort(checkSum.shortValue());

        return buffer;
    }
}
